package svc

import (
	_ "github.com/lib/pq"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"xialou_platform/services/address/model"
	"xialou_platform/services/address/rpc/internal/config"
)

type ServiceContext struct {
	Config        config.Config
	ProvinceModel model.ProvinceModel
	CityModel     model.CityModel
	CountyModel   model.CountyModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewSqlConn("postgres", c.Postgres.DataSource)
	return &ServiceContext{
		Config:        c,
		ProvinceModel: model.NewProvinceModel(conn, c.CacheRedis),
		CityModel:     model.NewCityModel(conn, c.CacheRedis),
		CountyModel:   model.NewCountyModel(conn, c.CacheRedis),
	}
}
